package com.example.ixform.dao;


import com.example.ixform.dto.IdolProduction;
import com.example.ixform.entities.Idol;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface IdolRepository extends CrudRepository<Idol, Long> {


    

    @Override
    List<Idol> findAll();
    @Query(nativeQuery = true,value = "SELECT i.name, i.age as age, COUNT(pi.idol_id) as productionCount " +
            "FROM idol i left join production_idol pi ON pi.idol_id = i.idol_id " +
            "GROUP BY i.name, i.age ORDER BY 3 DESC;")
    List<IdolProduction> idolProductions();



    Idol findByIdolId(long theId);
}
